/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}


/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _Niubi = __webpack_require__(1);

	var getRandom = function getRandom(min, max) {
	    return Math.floor(Math.random() * (max - min + 1)) + min;
	};

	//游戏最开始的定义
	var canvas = document.getElementById("myGame");
	var game = new _Niubi.Game(1200, 600, canvas, { preload: preload, create: create, update: update, render: render });
	window.game = game;
	//游戏资源（如图片）的加载
	function preload() {
	    game.load.image('bird', './img/bird.png').image('man', './img/man/man_ID.png', 10).image('manWhite', './img/man_white/man_ID.png', 10).image('bat', './img/bat/bat_ID.png', 8);
	}

	var man;
	var bat;
	var bird;
	var road = [];
	game.init();
	game.start();

	//场景、角色等的创建
	function create() {
	    //添加图片诠释角色
	    bat = game.add.sprite({
	        x: 0,
	        y: 100,
	        image: this.bat,
	        w: 50,
	        h: 50
	    });
	    bat.movement = true; //是否图片需要切换
	    bat.speedX = 1;

	    man = game.add.sprite({
	        x: 400,
	        y: 400,
	        color: 'black',
	        image: this.man,
	        w: 80,
	        h: 80
	    });
	    man.movement = true;

	    for (var i = 0; i < 4; i++) {
	        road[i] = game.add.building({
	            x: 350 * i,
	            y: 470,
	            color: Math.random() > 0.5 ? "black" : "white",
	            speedX: -4,
	            draw: function draw(ctx) {
	                ctx.save();
	                ctx.beginPath();
	                ctx.fillStyle = this.color; /*设置填充颜色*/
	                ctx.strokeStyle = this.color;
	                ctx.arc(this.x, this.y + 5, 5, 0, 2 * Math.PI);
	                ctx.arc(this.x + 200, this.y + 5, 5, 0, 2 * Math.PI);
	                ctx.fill();
	                ctx.fillRect(this.x, this.y, 200, 10); /*绘制一个矩形，前两个参数决定开始位置，后两个分别是矩形的宽和高*/
	                ctx.closePath(); /*可选步骤，关闭绘制的路径*/
	                ctx.stroke();
	                ctx.restore();
	            }
	        });
	    }
	}

	function update() {}
	//game.addSprite(200, 100, "imgBird");


	//游戏内各种判断
	function render() {
	    //蝙蝠变大
	    if (bat.w < 200) {
	        bat.w = ++bat.h;
	    }
	    //蝙蝠循环出现
	    if (bat.x > 1400) {
	        bat.x = -50;
	        bat.w = bat.h = 50;
	    }
	    //角色死亡
	    if (man.y > 600 || man.y < 0) {
	        man.inWorld = false;
	        man.alive = false;
	    }
	    //debug helper
	    if (!man.alive) {
	        game.stop();
	        console.log("game over!");
	    }

	    //判断是否落在了桥上----------如果颜色不匹配，即使落在了桥上也是false
	    var onRoad = false;
	    var roadColor = "";
	    for (var i = 0; i < 4; i++) {
	        var a = road[i].y - man.y;
	        if (road[i].x < man.x + man.w && man.x < road[i].x + 200 && 50 <= a && a < 80 && road[i].color == man.color) {
	            onRoad = true;
	            roadColor = road[i].color;
	            if (roadColor == "white") {
	                this.score += 200;
	            } else {
	                this.score += 100;
	            }
	        } else {
	            //console.log("未跳在桥上");
	        }
	    }
	    if (onKeyDown) {
	        //按下跳跃键
	        if (!jump) {
	            //如果不是跳跃状态
	            //跳跃状态为真，获得向上的爆发速度，向右的速度，和向上的加速度
	            jump = true;
	            man.speedY = -4;
	            man.gravity = -0.04;
	            man.speedX = 1;
	        }
	    } else {
	        if (onRoad) {
	            //在桥上，人物停止，不是跳跃状态
	            jump = false;
	            man.gravity = 0;
	            man.speedY = 0;
	            //if(roadColor == "white"){
	            //    man.speedX = 1;
	            //}else{
	            //    man.speedX = -1;
	            //}
	            man.speedX = -3;
	        } else {
	            //不在桥上，获得向下的加速度，向右的速度
	            man.gravity = 0.2;
	            man.speedX = 1;
	        }
	    }

	    //桥的循环，新生成的桥高度随机，颜色随机
	    if (road[0].x < -200) {
	        road[0].x = 1200;
	        road[0].y = getRandom(400, 500);
	        road[0].color = Math.random() > 0.5 ? "black" : "white";
	        var first = road.shift();
	        road.push(first);
	    }
	}
	var onKeyDown = false;
	var jump = false;
	function getEle(name) {
	    return document.getElementsByClassName(name)[0];
	}
	var hint = getEle("hint");
	var eleRestart = getEle("restart");
	var gameplay = getEle("gameplay");
	eleRestart.onclick = function () {
	    game.restart();
	};
	gameplay.onclick = function () {
	    game.gamePlay = true;
	    game.restart();
	};
	window.document.onkeydown = function (keyEvent) {
	    keyEvent = keyEvent ? keyEvent : window.event;
	    //keyEvent.which = keyEvent.which ? keyEvent.which : keyEvent.keyCode;
	    if (keyEvent.which == 13) {
	        onKeyDown = true;
	    } else if (keyEvent.which == 32) {
	        if (man.color == "black") {
	            man.image = game.manWhite;
	            man.color = "white";
	        } else {
	            man.image = game.man;
	            man.color = "black";
	        }
	    }
	};
	window.document.onkeyup = function (keyEvent) {
	    keyEvent = keyEvent ? keyEvent : window.event;
	    //keyEvent.which = keyEvent.which ? keyEvent.which : keyEvent.keyCode;
	    if (keyEvent.which == 13) {
	        //man.speedY = -1;
	        //man.gravity = 0.01;
	        onKeyDown = false;
	    }
	};

/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

	"use strict";

	Object.defineProperty(exports, "__esModule", {
	    value: true
	});
	exports.Game = undefined;

	var _createClass2 = __webpack_require__(2);

	var _createClass3 = _interopRequireDefault(_createClass2);

	var _assign = __webpack_require__(6);

	var _assign2 = _interopRequireDefault(_assign);

	var _classCallCheck2 = __webpack_require__(20);

	var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

	window.requestAnimFrame = function () {
	    return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function ( /* function FrameRequestCallback */callback, /* DOMElement Element */element) {
	        return window.setTimeout(callback, 1000 / 60);
	    };
	}();

	var Sprite = function Sprite(source) {
	    (0, _classCallCheck3.default)(this, Sprite);

	    this.image = {};
	    this.currentImage = 0;
	    this.movement = false;
	    this.color = '';
	    this.x = 0;
	    this.y = 0;
	    this.angle = 0;
	    this.rotation = 0;
	    this.alive = true;
	    this.inWorld = true;
	    this.a = 0;
	    this.gravity = 0;
	    this.speedX = 0;
	    this.speedY = 0;
	    (0, _assign2.default)(this, source);
	    this.w = this.w || this.image.width;
	    this.h = this.h || this.image.height;
	};

	var Game = function () {
	    function Game(width, height, element, object) {
	        var _this = this;

	        (0, _classCallCheck3.default)(this, Game);

	        this.sprite = [];
	        this.building = [];
	        this.width = element.width = width;
	        this.height = element.height = height;
	        this.ctx = element.getContext("2d");
	        this.preload = object.preload;
	        this.create = object.create;
	        this.update = object.update;
	        this.render = object.render;
	        this.score = 0;
	        this.state = {
	            start: false,
	            pause: false,
	            end: false
	        };
	        this.gamePlay = false;
	        this.gameOver = false;
	        this.load = {
	            image: function image(name, src) {
	                var num = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

	                if (!(name in _this)) _this[name] = [];
	                var onlyOne = num == 1;
	                for (var i = 0; i < num; i++) {
	                    _this.imageLoaded = false;
	                    var newImg = new Image();
	                    newImg.onload = function () {
	                        return _this.imageLoaded = true;
	                    };
	                    newImg.src = onlyOne ? src : src.replace(/ID/, i);
	                    console.log("加载完成：" + name);
	                    _this[name].push(newImg);
	                }
	                return _this.load;
	            }
	        };
	        this.add = {
	            sprite: function sprite(source) {
	                var newSprite = new Sprite(source);
	                _this.sprite.push(newSprite);
	                return newSprite;
	            },
	            building: function building(source) {
	                var newSprite = new Sprite(source);
	                _this.building.push(newSprite);
	                return newSprite;
	            }
	        };
	    }

	    (0, _createClass3.default)(Game, [{
	        key: "gameLoop",
	        value: function gameLoop() {
	            var _this2 = this;

	            var gameLoop = function gameLoop() {
	                count++;
	                _this2.T = requestAnimFrame(gameLoop);
	                if (!_this2.gameOver) {
	                    _this2.update();
	                    _this2.render();
	                    _this2.ctx.clearRect(0, 0, _this2.width, _this2.height);
	                    _this2.drawText();
	                    for (var i = 0; i < _this2.sprite.length; i++) {
	                        var CS = _this2.sprite[i];
	                        CS.speedX += CS.a;
	                        CS.speedY += CS.gravity;
	                        CS.x += CS.speedX;
	                        CS.y += CS.speedY;
	                        _this2.ctx.drawImage(CS.image[CS.currentImage], CS.x, CS.y, CS.w, CS.h);
	                        if (CS.movement && count % 3 == 0) {
	                            CS.currentImage++;
	                            if (CS.currentImage >= CS.image.length) {
	                                CS.currentImage = 0;
	                            }
	                        }
	                    }
	                    for (var _i = 0; _i < _this2.building.length; _i++) {
	                        var currentBuild = _this2.building[_i];
	                        currentBuild.x += currentBuild.speedX;
	                        currentBuild.y += currentBuild.speedY;
	                        currentBuild.draw(_this2.ctx);
	                    }
	                } else {
	                    //hint.style.display = "block";
	                }
	            };
	            gameLoop();
	        }
	    }, {
	        key: "drawText",
	        value: function drawText() {
	            this.ctx.save();
	            //分数显示
	            this.ctx.fillStyle = "#ffffff";
	            this.ctx.font = "24px YouYuan";
	            this.ctx.fillText("分数:" + this.score, 1000, 50);
	            this.ctx.font = "18px YouYuan";
	            this.ctx.fillStyle = "#cccccc";
	            this.ctx.fillText("玩法介绍:", 1000, 100);
	            //玩法介绍
	            if (!this.gamePlay) {
	                this.ctx.fillText("我才不得告诉你→_→", 1000, 130);
	                this.ctx.fillText("除非……", 1000, 160);
	                this.ctx.fillText("你死了一百次以上", 1000, 190);
	                this.ctx.fillText("或者……", 1000, 220);
	                this.ctx.fillText("承认你很弱！嘻嘻嘻嘻", 1000, 250);
	            } else {
	                this.ctx.fillText("-------Y(^_^)Y-------", 1000, 130);
	                this.ctx.fillText("切换颜色：空格键", 1000, 160);
	                this.ctx.fillText("跳    跃：Enter键", 1000, 190);
	                this.ctx.fillText("人物颜色必须和桥的颜色", 1000, 220);
	                this.ctx.fillText("相同！", 1000, 250);
	                this.ctx.fillText("人在空中不能跳跃！", 1000, 280);
	                this.ctx.fillText("出来就死不是BUG！", 1000, 310);
	                this.ctx.fillText("是在考验你的人品……", 1000, 340);
	                this.ctx.fillText("-------- ^_^ --------", 1000, 370);
	            }
	            //提示游戏结束
	            if (this.gameOver) {
	                this.alpha += count * 0.0005;
	                if (this.alpha > 1) this.alpha = 1;
	                this.ctx.font = "34px YouYuan";
	                this.ctx.fillStyle = "#ffffff";
	                this.ctx.shadowBlur = 10;
	                this.ctx.shadowColor = "white";
	                this.ctx.fillStyle = "rgba(255,255,255," + this.alpha + ")";
	                this.ctx.fillText("GAME OVER!", this.width * 0.5 - 80, this.height * 0.4);
	            }
	            this.ctx.restore();
	        }
	    }, {
	        key: "init",
	        value: function init() {
	            this.preload();
	            this.create();
	        }
	    }, {
	        key: "start",
	        value: function start() {
	            this.gameLoop();
	        }
	    }, {
	        key: "restart",
	        value: function restart() {
	            hint.style.display = "none";
	            this.score = 0;
	            this.sprite = [];
	            this.buliding = [];
	            this.create();
	            this.gameOver = false;
	        }
	    }, {
	        key: "stop",
	        value: function stop() {
	            this.gameOver = true;
	        }
	    }]);
	    return Game;
	}();

	exports.Game = Game;

	var count = 0;

/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {

	"use strict";

	exports.__esModule = true;

	var _defineProperty = __webpack_require__(3);

	var _defineProperty2 = _interopRequireDefault(_defineProperty);

	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

	exports.default = function () {
	  function defineProperties(target, props) {
	    for (var i = 0; i < props.length; i++) {
	      var descriptor = props[i];
	      descriptor.enumerable = descriptor.enumerable || false;
	      descriptor.configurable = true;
	      if ("value" in descriptor) descriptor.writable = true;
	      (0, _defineProperty2.default)(target, descriptor.key, descriptor);
	    }
	  }

	  return function (Constructor, protoProps, staticProps) {
	    if (protoProps) defineProperties(Constructor.prototype, protoProps);
	    if (staticProps) defineProperties(Constructor, staticProps);
	    return Constructor;
	  };
	}();

/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {

	module.exports = { "default": __webpack_require__(4), __esModule: true };

/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {

	var $ = __webpack_require__(5);
	module.exports = function defineProperty(it, key, desc){
	  return $.setDesc(it, key, desc);
	};

/***/ },
/* 5 */
/***/ function(module, exports) {

	var $Object = Object;
	module.exports = {
	  create:     $Object.create,
	  getProto:   $Object.getPrototypeOf,
	  isEnum:     {}.propertyIsEnumerable,
	  getDesc:    $Object.getOwnPropertyDescriptor,
	  setDesc:    $Object.defineProperty,
	  setDescs:   $Object.defineProperties,
	  getKeys:    $Object.keys,
	  getNames:   $Object.getOwnPropertyNames,
	  getSymbols: $Object.getOwnPropertySymbols,
	  each:       [].forEach
	};

/***/ },
/* 6 */
/***/ function(module, exports, __webpack_require__) {

	module.exports = { "default": __webpack_require__(7), __esModule: true };

/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {

	__webpack_require__(8);
	module.exports = __webpack_require__(11).Object.assign;

/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {

	// 19.1.3.1 Object.assign(target, source)
	var $export = __webpack_require__(9);

	$export($export.S + $export.F, 'Object', {assign: __webpack_require__(14)});

/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {

	var global    = __webpack_require__(10)
	  , core      = __webpack_require__(11)
	  , ctx       = __webpack_require__(12)
	  , PROTOTYPE = 'prototype';

	var $export = function(type, name, source){
	  var IS_FORCED = type & $export.F
	    , IS_GLOBAL = type & $export.G
	    , IS_STATIC = type & $export.S
	    , IS_PROTO  = type & $export.P
	    , IS_BIND   = type & $export.B
	    , IS_WRAP   = type & $export.W
	    , exports   = IS_GLOBAL ? core : core[name] || (core[name] = {})
	    , target    = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE]
	    , key, own, out;
	  if(IS_GLOBAL)source = name;
	  for(key in source){
	    // contains in native
	    own = !IS_FORCED && target && key in target;
	    if(own && key in exports)continue;
	    // export native or passed
	    out = own ? target[key] : source[key];
	    // prevent global pollution for namespaces
	    exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key]
	    // bind timers to global for call from export context
	    : IS_BIND && own ? ctx(out, global)
	    // wrap global constructors for prevent change them in library
	    : IS_WRAP && target[key] == out ? (function(C){
	      var F = function(param){
	        return this instanceof C ? new C(param) : C(param);
	      };
	      F[PROTOTYPE] = C[PROTOTYPE];
	      return F;
	    // make static versions for prototype methods
	    })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
	    if(IS_PROTO)(exports[PROTOTYPE] || (exports[PROTOTYPE] = {}))[key] = out;
	  }
	};
	// type bitmap
	$export.F = 1;  // forced
	$export.G = 2;  // global
	$export.S = 4;  // static
	$export.P = 8;  // proto
	$export.B = 16; // bind
	$export.W = 32; // wrap
	module.exports = $export;

/***/ },
/* 10 */
/***/ function(module, exports) {

	// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
	var global = module.exports = typeof window != 'undefined' && window.Math == Math
	  ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
	if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef

/***/ },
/* 11 */
/***/ function(module, exports) {

	var core = module.exports = {version: '1.2.6'};
	if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef

/***/ },
/* 12 */
/***/ function(module, exports, __webpack_require__) {

	// optional / simple context binding
	var aFunction = __webpack_require__(13);
	module.exports = function(fn, that, length){
	  aFunction(fn);
	  if(that === undefined)return fn;
	  switch(length){
	    case 1: return function(a){
	      return fn.call(that, a);
	    };
	    case 2: return function(a, b){
	      return fn.call(that, a, b);
	    };
	    case 3: return function(a, b, c){
	      return fn.call(that, a, b, c);
	    };
	  }
	  return function(/* ...args */){
	    return fn.apply(that, arguments);
	  };
	};

/***/ },
/* 13 */
/***/ function(module, exports) {

	module.exports = function(it){
	  if(typeof it != 'function')throw TypeError(it + ' is not a function!');
	  return it;
	};

/***/ },
/* 14 */
/***/ function(module, exports, __webpack_require__) {

	// 19.1.2.1 Object.assign(target, source, ...)
	var $        = __webpack_require__(5)
	  , toObject = __webpack_require__(15)
	  , IObject  = __webpack_require__(17);

	// should work with symbols and should have deterministic property order (V8 bug)
	module.exports = __webpack_require__(19)(function(){
	  var a = Object.assign
	    , A = {}
	    , B = {}
	    , S = Symbol()
	    , K = 'abcdefghijklmnopqrst';
	  A[S] = 7;
	  K.split('').forEach(function(k){ B[k] = k; });
	  return a({}, A)[S] != 7 || Object.keys(a({}, B)).join('') != K;
	}) ? function assign(target, source){ // eslint-disable-line no-unused-vars
	  var T     = toObject(target)
	    , $$    = arguments
	    , $$len = $$.length
	    , index = 1
	    , getKeys    = $.getKeys
	    , getSymbols = $.getSymbols
	    , isEnum     = $.isEnum;
	  while($$len > index){
	    var S      = IObject($$[index++])
	      , keys   = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S)
	      , length = keys.length
	      , j      = 0
	      , key;
	    while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key];
	  }
	  return T;
	} : Object.assign;

/***/ },
/* 15 */
/***/ function(module, exports, __webpack_require__) {

	// 7.1.13 ToObject(argument)
	var defined = __webpack_require__(16);
	module.exports = function(it){
	  return Object(defined(it));
	};

/***/ },
/* 16 */
/***/ function(module, exports) {

	// 7.2.1 RequireObjectCoercible(argument)
	module.exports = function(it){
	  if(it == undefined)throw TypeError("Can't call method on  " + it);
	  return it;
	};

/***/ },
/* 17 */
/***/ function(module, exports, __webpack_require__) {

	// fallback for non-array-like ES3 and non-enumerable old V8 strings
	var cof = __webpack_require__(18);
	module.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){
	  return cof(it) == 'String' ? it.split('') : Object(it);
	};

/***/ },
/* 18 */
/***/ function(module, exports) {

	var toString = {}.toString;

	module.exports = function(it){
	  return toString.call(it).slice(8, -1);
	};

/***/ },
/* 19 */
/***/ function(module, exports) {

	module.exports = function(exec){
	  try {
	    return !!exec();
	  } catch(e){
	    return true;
	  }
	};

/***/ },
/* 20 */
/***/ function(module, exports) {

	"use strict";

	exports.__esModule = true;

	exports.default = function (instance, Constructor) {
	  if (!(instance instanceof Constructor)) {
	    throw new TypeError("Cannot call a class as a function");
	  }
	};

/***/ }
/******/ ]);